package cn.htsyb.synergy.maker.config;

import cn.htsyb.synergy.maker.config.meta.*;
import cn.htsyb.synergy.maker.util.PropertyUtil;
import cn.htsyb.synergy.maker.util.ResourceUtil;

public class Maker {
    private static Maker instance = null;
    private Author author = new Author();
    private Compile compile = new Compile();
    private Database database = new Database();
    private Regular regular = new Regular();
    private Template template = new Template();

    public static synchronized Maker getInstance() {
        if (instance == null) {
            instance = new Maker();
            instance.init();
        }
        return instance;
    }

    public static void setInstance(Maker instance) {
        Maker.instance = instance;
    }

    private void init() {

        author.setEmail(PropertyUtil.getString("maker.author.email", author.getEmail()));
        author.setName(PropertyUtil.getString("maker.author.name", author.getName()));
        author.setDate(PropertyUtil.getString("maker.author.date", author.getDate()));

        compile.setCurrentPackageRemark(PropertyUtil.getString("maker.compile.currentPackageRemark", compile.getCurrentPackageRemark()));
        compile.setCurrentPackage(PropertyUtil.getString("maker.compile.currentPackage", compile.getCurrentPackage()));
        compile.setMakerTablePattern(PropertyUtil.getStringArray("maker.compile.makerTablePattern", compile.getMakerTablePattern()));
        compile.setParentPackage(PropertyUtil.getString("maker.compile.parentPackage", compile.getParentPackage()));

        database.setCatalog(PropertyUtil.getString("maker.database.catalog", database.getCatalog()));
        database.setSchema(PropertyUtil.getString("maker.database.schema", database.getSchema()));
        database.setDriverClass(PropertyUtil.getString("maker.database.driverClass", database.getDriverClass()));
        database.setDriverUrl(PropertyUtil.getString("maker.database.driverUrl", database.getDriverUrl()));
        database.setPassword(PropertyUtil.getString("maker.database.password", database.getPassword()));
        database.setUsername(PropertyUtil.getString("maker.database.username", database.getUsername()));

        regular.setHumpConvertChar(PropertyUtil.getStringArray("maker.regular.humpConvertChar", regular.getHumpConvertChar()));
        regular.setFormFiledSizeOfRow(PropertyUtil.getInteger("maker.regular.formFiledSizeOfRow", regular.getFormFiledSizeOfRow()));
        regular.setSearchFiledSizeOfRow(PropertyUtil.getInteger("maker.regular.searchFiledSizeOfRow", regular.getSearchFiledSizeOfRow()));
        regular.setExcludeColumn(PropertyUtil.getStringArray("maker.regular.excludeColumn", regular.getExcludeColumn()));

        template.setEndSuffix(PropertyUtil.getString("maker.template.endSuffix", template.getEndSuffix()));
        template.setExportPath(ResourceUtil.convertToLocalPath((PropertyUtil.getString("maker.template.exportPath", template.getExportPath()))));
        template.setPrefixPath(ResourceUtil.convertToLocalPath((PropertyUtil.getString("maker.template.prefixPath", template.getPrefixPath()))));
        template.setGlobalExportPath(ResourceUtil.convertToLocalPath((PropertyUtil.getString("maker.template.globalExportPath", template.getGlobalExportPath()))));
        template.setGlobalPrefixPath(ResourceUtil.convertToLocalPath((PropertyUtil.getString("maker.template.globalPrefixPath", template.getGlobalPrefixPath()))));
    }

    public Author getAuthor() {
        return author;
    }

    public void setAuthor(Author author) {
        this.author = author;
    }

    public Compile getCompile() {
        return compile;
    }

    public void setCompile(Compile compile) {
        this.compile = compile;
    }

    public Database getDatabase() {
        return database;
    }

    public void setDatabase(Database database) {
        this.database = database;
    }

    public Regular getRegular() {
        return regular;
    }

    public void setRegular(Regular regular) {
        this.regular = regular;
    }

    public Template getTemplate() {
        return template;
    }

    public void setTemplate(Template template) {
        this.template = template;
    }
}
